#include "previewdirectionselector.h"
#include "ui_previewdirectionselector.h"

PreviewDirectionSelector::PreviewDirectionSelector(std::shared_ptr<STLModelWidget> parent)
    : m_sp_modelWidget(parent)
    , ui(new Ui::PreviewDirectionSelector)
{
    ui->setupUi(this);
    m_original_model_pos = m_sp_modelWidget->getCurrentCameraPos();
    m_original_model_center = m_sp_modelWidget->getCurrentCameraCenter();
    m_original_model_up = m_sp_modelWidget->getCurrentCameraUp();
    m_latest_model_pos = m_sp_modelWidget->getCurrentCameraPos();
    m_latest_model_center = m_sp_modelWidget->getCurrentCameraCenter();
    m_latest_model_up = m_sp_modelWidget->getCurrentCameraUp();
};

PreviewDirectionSelector::~PreviewDirectionSelector()
{
    delete ui;
}

void PreviewDirectionSelector::on_d1_minus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::D1, 90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_d1_plus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::D1, -90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_d2_minus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::D2, 90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_d2_plus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::D2, -90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_x_minus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::X, 90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_x_plus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::X, -90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_y_minus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::Y, 90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_y_plus_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(FixDirection::Y, -90);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}

void PreviewDirectionSelector::on_model_recover_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(m_latest_model_pos, m_latest_model_center, m_latest_model_up);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}


void PreviewDirectionSelector::on_record_latest_clicked()
{
    m_latest_model_pos = m_sp_modelWidget->getCurrentCameraPos();
    m_latest_model_center = m_sp_modelWidget->getCurrentCameraCenter();
    m_latest_model_up = m_sp_modelWidget->getCurrentCameraUp();
}


void PreviewDirectionSelector::on_recover_origin_clicked()
{
    m_sp_modelWidget->setCurrentCameraPos(m_original_model_pos, m_original_model_center, m_original_model_up);
    m_sp_modelWidget->updateLightPos(LightMoveMode_em::AsCamera);
    m_sp_modelWidget->update();
}

